<template>
  <div>
    <div>
      <div style="text-align: center; margin: 10px">
        {{ form.CheckTaskName }}
      </div>
      <div class="block-box">
        <div class="block-box_item">
          <van-cell-group :border="border">
            <van-field
              label="检查类型"
              class="input_text"
              :value="form.CheckTypeName"
              readonly
            />
            <van-field
              label="来源计划"
              class="input_text"
              autosize
              type="textarea"
              rows="1"
              v-if="form.CPID == null"
              :value="form.CheckPlanName"
              readonly
              @click="goFromDetail()"
              right-icon="arrow"
            />
            <van-field
              label="任务发起人"
              class="input_text"
              :value="form.CreateChnName"
              readonly
            />
            <van-field
              label="任务发起时间"
              class="input_text"
              :value="form.CreateDate"
              readonly
            />
            <van-field
              label="检查人"
              class="input_text"
              :value="form.CheckNames"
              type="textarea"
              rows="1"
              :autosize="true"
              readonly
            />
            <van-field
              label="检查时间段"
              class="input_text"
              rows="1"
              autosize
              type="textarea"
              :value="form.StartDate + '至' + form.EndDate"
              readonly
            />
            <van-field
              label="检查要求"
              class="input_text"
              :value="form.CheckRequirement || '暂无检查要求'"
              readonly
            />
            <van-field
              label="检查记录"
              class="input_text"
              :value="
                '隐患：' + form.HiddenDangerCnt + ' /检查：' + form.CheckCnt
              "
              right-icon="arrow"
              readonly
              @click="goMyTaskHistoryList()"
            />
            <van-field
              label="检查现场照片"
              class="input_text"
              :value="'已上传' + form.PhotoCnt + '张现场照片'"
              readonly
              right-icon="arrow"
              @click="goMyTaskFileList()"
            />
            <van-field
              label="是否统计"
              class="input_text"
              :value="WhetherStatistical(form.WhetherStatistical)"
              readonly
            />
          </van-cell-group>
        </div>
      </div>

      <div
        class="block-box"
        v-if="form.Templates.length > 0"
      >
        <div class="block-box_item">
          <div class="block-box_title">已分配的检查表</div>
          <div class="operate_list">
            <van-row
              v-for="(item, index) in form.Templates"
              :key="index"
              class="operate_row"
              @click="goCheckResult(item)"
            >
              <van-col span="1">{{ index + 1 }}</van-col>
              <van-col
                offset="1"
                span="17"
              >
                <div class="f16">{{ item.TName }}</div>
                <div class="mt-10">类型：{{ item.CheckTypeName }}</div>
                <div class="mt-10">
                  检查进度：共{{ item.TotalCnt }}项，已查{{
                    item.CheckCnt
                  }}项，异常{{ item.DangerCnt }}项
                </div>
              </van-col>
              <van-col
                offset="1"
                span="4"
              >
                <van-tag
                  v-if="item.Status ==0"
                  size="mini"
                  type="primary"
                >未完成</van-tag>
                <van-tag
                  v-if="item.Status == 5"
                  size="mini"
                  type="warning"
                >进行中</van-tag>
                <van-tag
                  v-if="item.Status == 10"
                  size="mini"
                  type="success"
                >已完成</van-tag>
              </van-col>
            </van-row>
          </div>
        </div>
      </div>
      <div
        class="btns m-10"
        v-if="this.form.Status == 10 && !isDate"
      >
        <van-button
          type="green2"
          @click="goTakePhoto()"
        > 随手拍 </van-button>
        <van-button
          class="ml-10"
          @click="goCheckList()"
        >
          检查表检查
        </van-button>
      </div>
      <div
        class="btns m-10"
        v-if="this.form.Status == 10 && !isDate"
      >
        <van-button
          type="green"
          @click="handleClose()"
        > 结束任务 </van-button>
        <van-button
          class="ml-10"
          @click="NotInStatistical()"
        >
          任务执行确认
        </van-button>
      </div>
      <!-- <div
        class="btns ml-10 mr-10 mb-10"
        v-if="this.form.Status == 10 && !isDate"
      >
        <van-button type="green" @click="handleClose()"> 结束任务 </van-button>
      </div> -->
    </div>
  </div>
</template>

<script>
import {
  getDetail,
  handleClose,
  NotInStatistical,
} from "@/api/sytech/sytechDangerCheckTask";
import { getDateTime } from "@/utils/getDate";
import { Dialog } from "vant";
import { mapGetters } from "vuex";

// import { deepClone } from "@/utils";
export default {
  components: {},
  data() {
    return {
      baseUrl: process.env.VUE_APP_BASE_API,
      id: this.$route.query.id,
      isDate: true,
      border: false,
      form: {
        Templates: [],
      },
    };
  },
  computed: {
    ...mapGetters(["CompanyCode"]),
  },
  created() {
    this.isDate = this.$route.query.isDate;
    this.geDetail();
  },
  methods: {
    goMyTaskFileList() {
      this.$router.push(
        "/SytechDanger/DangerCheckTaskFileList?ctCode=" + this.form.CTCode
      );
    },

    goMyTaskHistoryList() {
      this.$router.push({
        path: "/SytechDanger/DangerCheckTaskDetailList",
        query: {
          ctCode: this.form.CTCode,
        },
      });
    },
    // 随手拍
    goTakePhoto() {
      this.$router.push({
        path: "/SytechDanger/DangerCheckTaskDetailEdit",
        query: { ctCode: this.form.CTCode, originType: 3 },
      });
    },

    goCheckList() {
      this.$router.push(
        "/SytechDanger/DangerCheckTaskTemplateList?ctCode=" + this.form.CTCode
      );
    },

    // 获取详情
    geDetail() {
      getDetail({ id: this.id }).then((res) => {
        this.form = res.data;
        this.form.StartDate = getDateTime(this.form.StartDate);
        this.form.EndDate = getDateTime(this.form.EndDate);
        this.form.CreateDate = getDateTime(this.form.CreateDate);
      });
    },
    goFromDetail(item) {
      //  this.$toast("暂无来源计划AA"+"=="+this.form.CpID);
      if (this.form.CpID) {
        this.$router.push(
          "/SytechDanger/DangerCheckPlanView?cpId=" + this.form.CpID
        );
      } else {
        this.$toast("暂无来源计划");
      }
    },

    goCheckResult(item) {
      if (item.Status < 10) {
        this.$router.push({
          path: "/SytechDanger/DangerCheckTemplateDetail",
          query: {
            tCode: item.TCode,
            tRand: item.TRand,
            CompanyCode: this.CompanyCode,
            ctCode: this.form.CTCode,
          },
        });
      } else {
        this.$router.push(
          "/SytechDanger/DangerTemplateCheckResult?tCode=" +
            item.TCode +
            "&tRand=" +
            item.TRand
        );
      }
    },
    handleClose() {
      Dialog.confirm({
        title: "询问",
        message: "您确定要结束当前检查任务吗?",
      })
        .then(() => {
          // on confirm
          handleClose({ id: this.form.ID }).then((res) => {
            this.$toast.success("结束成功！");
            this.$router.goRefresh();
            // console.log('asdasdsad',res);
          });
        })
        .catch(() => {
          // on cancel
        });
    },
    NotInStatistical() {
      Dialog.confirm({
        title: "询问",
        confirmButtonText: "是",
        cancelButtonText: "否",
        message:
          " 请确认该任务今日是否需执行？说明：当班产线停线、领班未上班时请选择“否”，其他情况请选择“是”。",
      })
        .then(() => {})
        .catch(() => {
          NotInStatistical({ id: this.form.ID }).then((res) => {
            this.$toast.success("操作成功！");
            this.$router.goRefresh();
            // console.log('asdasdsad',res);
          });
        });
    },
    WhetherStatistical(value) {
      if (value == false) {
        return "否";
      } else {
        return "是";
      }
    },
  },
};
</script>

<style lang="less" scoped>
/*
        .main {
            height: 100vh;
        }
    */
.bottom-btns {
  margin-top: 10px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .submit-btn {
    width: 32%;
    height: 35px;
    font-size: 14px;
  }
  .delete-btn {
    width: 100%;
    height: 35px;
    font-size: 14px;
  }
}
.det_top_box {
  padding: 10px;
  background-color: #e8f1f8;
}

.detail_header {
  color: #ffffff;
  background: url("../../../assets/Images/AppIcon/image_riskunit_detail_bg.png");
  background-size: cover;
  padding: 10px;
  border-radius: 5px;
  /*background-color: #fff;*/

  .det_top {
    display: flex;
    justify-content: space-between;

    .dep_top_img {
      height: 20px;
      width: 20px;
      margin-right: 5px;
    }
  }

  .det_name {
    margin-top: 20px;
    text-align: center;
  }

  .det_location {
    text-align: center;
    margin-bottom: 20px;
  }
}

.det_tab {
  padding: 10px;
  .det_tab_item {
    padding: 10px 0;
    background-color: #fff;
    border-radius: 5px;
    margin-bottom: 10px;

    .det_tab_item_text {
      padding: 0 10px;
    }
  }
}
.text_box {
  padding: 10px;
  border-radius: 5px;
  /*background-color: #e8f1f8;*/
  margin-bottom: 10px;

  .text_top {
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    .top_link {
      color: #1989fa;
    }
  }

  .text_item {
    display: flex;
    justify-content: space-between;
    margin-left: 10px;

    .item_link {
      color: #1989fa;
    }
  }

  .text_img {
    display: flex;
    align-items: center;

    .img_item {
      width: 33.3%;
      text-align: center;

      img {
        height: 25px;
        width: 25px;
        margin-bottom: 10px;
      }
    }
  }

  .text_history {
    display: flex;
    vertical-align: middle;
    margin-bottom: 10px;
  }

  .text_member {
    color: #1989fa;
    margin-bottom: 10px;
  }

  .text_total_img {
    display: flex;
    align-items: center;

    .img_item {
      width: 33.3%;
      text-align: center;

      .img_item_top {
        display: flex;
        vertical-align: middle;
        margin-bottom: 10px;
      }
      img {
        height: 15px;
        width: 15px;
        margin-right: 5px;
      }
    }
  }
  .text_record_list {
    .list_row {
      display: flex;
      justify-content: space-between;
      margin-bottom: 10px;
      > div {
        width: 33.3%;
      }
      .row_center {
        text-align: center;
      }
      .row_right {
        text-align: right;
      }
    }
  }
}
.operate_list {
  font-size: 12px;
  border: 1px solid #e8f1f8;
  .operate_row_first {
    padding: 10px;
    background-color: #e8f1f8;
    border-bottom: 1px solid #e8f1f8;
    margin-bottom: 10px;
  }
  .operate_row {
    padding: 10px;
    border-bottom: 1px solid #e8f1f8;
    /*margin-bottom: 10px;*/
  }
}
</style>
